package com.example.day1_dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class PicDialog extends Dialog {
    private ImageView iv;
    private TextView tv;
    private String url,title;
    private MyLongListener myLongListener;

    public PicDialog setMyLongListener(MyLongListener myLongListener) {
        this.myLongListener = myLongListener;
        return this;
    }

    public PicDialog setUrl(String url) {
        this.url = url;
        return this;
    }

    public PicDialog setTitle(String title) {
        this.title = title;
        return this;
    }

    public PicDialog(@NonNull Context context) {
        super(context);
    }

    public PicDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected PicDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_pic);
        iv = findViewById(R.id.iv);
        tv = findViewById(R.id.tv);
        tv.setText(title);
        Glide.with(getContext()).load(url).into(iv);

        iv.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                //不处理
                if(myLongListener != null){
                    myLongListener.onLongClick();
                }


                return true;
            }
        });


    }

    interface  MyLongListener{
        void onLongClick();
    }
}
